<?php
namespace \DragonU\Plugin;
/**
 * Plugin implementation based on the way WordPress handles Filters and Actions.
 *
 * @internal
 * Copyright (c) 2009, Jacob Santos
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
 *  * Redistributions of source code must retain the above copyright notice, this list of conditions
 *    and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other materials provided
 *    with the distribution.
 *  * Neither the name of the DragonU nor the names of its contributors may be used to endorse or
 *    promote products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @author Jacob Santos <wordpress@santosj.name>
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD license
 * @package DragonU
 * @subpackage Plugin
 * @since 0.1
 */

/**
 * Plugin implementation.
 *
 * Actions are events that do not return anything, but can accept parameters.
 * Filters are hooks that accept content and must return content. They can apply
 * changes to the content before passing it along. Pluggable plugins are classes
 * and functions which only have one implementation and accept parameters.
 *
 * The Pluggable implementation is implemented in such a way that there is
 * almost no overhead in calling the implementations.
 *
 * @author Jacob Santos <wordpress@santosj.name>
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD license
 * @package CorePress
 * @subpackage Plugin
 * @since 0.1
 */
class Plugin
{
	/**
	 * Contains the action class.
	 *
	 * @since 0.1
	 * @var \CorePress\Plugin\Action
	 */
	static public $action = null;

	/**
	 * Contains the filter class.
	 *
	 * @since 0.1
	 * @var \CorePress\Plugin\Filter
	 */
	static public $filter = null;

	/**
	 * Contains the pluggable class.
	 *
	 * @since 0.1
	 * @var \CorePress\Plugin\Pluggable
	 */
	static public $pluggable = null;

	/**
	 * Sets the static attributes to their classes, if they haven't already.
	 *
	 * @since 0.1
	 *
	 * @return \CorePress\Plugin
	 */
	public function __construct()
	{
		if( ! isset(static::$action) )
		{
			static::$action = new Plugin\Action();
		}

		if( ! isset(static::$filter) )
		{
			static::$filter = new Plugin\Filter();
		}

		if( ! isset(static::$pluggable) )
		{
			static::$pluggable = null;
		}
	}

	/**
	 * Retrieve actions.
	 *
	 * @since 0.1
	 *
	 * @return \CorePress\Plugin\Action
	 */
	public function action()
	{
		return static::$action;
	}

	/**
	 * Retrieve filters.
	 *
	 * @since 0.1
	 *
	 * @return \CorePress\Plugin\Filter
	 */
	public function filter()
	{
		return static::$filter;
	}

	/**
	 * Retrieve pluggable functions and classes.
	 *
	 * @since 0.1
	 *
	 * @return \CorePress\Plugin\Pluggable
	 */
	public function pluggable()
	{
		return static::$pluggable;
	}

}